String.prototype.trim = function () {
  return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};

// -- Pants --------------------------------------------------------------------
var Pants = {
  hideInfoBox: function (infobox) {
    infobox.style.display = 'none';
  },

  hotkey: function(e) {
    if (!e.ctrlKey || !e.altKey) { return; }

    switch (e.keyCode) {
      // Ctrl+Alt+A: Display the admin toolbar.
      case 'A'.charCodeAt():
        Pants.toggleAdminToolbar();
        break;

      // Ctrl+Alt+C: Recent comments.
      case 'C'.charCodeAt():
        window.location = YAHOO.util.Dom.get('link-recent-comments').href;
        break;
    }
  },

  showInfoBox: function (infobox) {
    infobox.style.display = 'inline';
  },

  toggleAdminToolbar: function () {
    var toolbar  = YAHOO.util.Dom.get('adminToolbar'),
        username = YAHOO.util.Dom.get('username');

    if (YAHOO.util.Dom.hasClass(toolbar, 'hidden')) {
      YAHOO.util.Dom.removeClass(toolbar, 'hidden');
      if (username) { username.focus(); }
    }
    else {
      YAHOO.util.Dom.addClass(toolbar, 'hidden');
      if (username) { username.blur(); }
    }
  }
};

// -- Global Scope -------------------------------------------------------------
YAHOO.util.Event.addListener(window, 'keyup', Pants.hotkey);
